//
//  I_Admin.m
//  YunDongAdmin
//
//  Created by lqq on 2018/9/7.
//  Copyright © 2018年 cloudfighting.com. All rights reserved.
//

#import "I_Admin.h"

@implementation I_Admin

/**
 管理员创建账户
 */
+ (NetworkTask *)creatAdminWithAdmin:(M_Admin *)admin success:(void(^)(void))successBlock failure:(ErrorBlock)failureBlock
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:[admin toDictionary]];
    [params safeSetObject:RI.currentGym.gymId forKey:@"gymId"];
    return [NET POST:@"/gym-coach-api/admin/1.0.0/createAccount" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

/**
 管理员删除账户
 */
+ (NetworkTask *)deleteAdminWithAdminId:(NSString *)adminId success:(void(^)(void))successBlock failure:(ErrorBlock)failureBlock
{
    NSDictionary *params = @{@"accountId":SAFE_NIL_STRING(adminId)};
    return [NET POST:@"/gym-coach-api/admin/1.0.0/deleteAccount" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

/**
 重置密码
 */
+ (NetworkTask *)resetPasswordWithAdminId:(NSString *)adminId
                                adminType:(AdminType)adminType
                                  success:(void(^)(void))successBlock
                                  failure:(ErrorBlock)failureBlock
{
    NSDictionary *params = @{@"accountId":SAFE_NIL_STRING(adminId),@"roleId":@(adminType)};
    return [NET POST:@"/gym-coach-api/admin/1.0.0/pwdReset" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}
/**
 查询管理员详情
 */
+ (NetworkTask *)requestAdminDetailWithAdminId:(NSString *)adminId success:(void(^)(M_Admin *admin))successBlock failure:(ErrorBlock)failureBlock
{
    NSDictionary *params = @{@"accountId":SAFE_NIL_STRING(adminId)};
    return [NET POST:@"/gym-coach-api/admin/1.0.0/listAccountDetail" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            M_Admin *admin = [[M_Admin alloc] initWithDictionary:SAFE_VALUE_FOR_KEY(resultObject, @"data") error:nil];
            successBlock(admin);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}


/**
 管理端修改账户信息
 */
+ (NetworkTask *)updateAdminWithAdmin:(M_Admin *)admin success:(void(^)(void))successBlock failure:(ErrorBlock)failureBlock
{
    NSDictionary *params = [admin toDictionary];
    return [NET POST:@"/gym-coach-api/admin/1.0.0/updateAccount" parameters:params criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}

/**
 查询门店的店长和教练列表
 */
+ (NetworkTask *)requestGymAdminListAndGymCoachListOnSuccess:(void(^)(NSMutableArray *adminList,NSMutableArray *coachList))successBlock failure:(ErrorBlock)failureBlock
{
    return [NET POST:@"/gym-coach-api/admin/1.0.0/listAccount" parameters:@{@"currentPage":@(1),@"pageSize":@(200)} criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        if (successBlock) {
            NSMutableArray *adminList = [M_Admin arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(SAFE_VALUE_FOR_KEY(resultObject, @"data"), @"adminList") error:nil];
            NSMutableArray *coachList = [M_Coach arrayOfModelsFromDictionaries:SAFE_VALUE_FOR_KEY(SAFE_VALUE_FOR_KEY(resultObject, @"data"), @"coachList") error:nil];
            successBlock(adminList,coachList);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];
}
@end
